//此处把获到openId，与检索用户信息分开成两个函数
function getOpenid() {
  var app = getApp()   
  wx.clearStorage()
  var that = this
  var p = new Promise(function (resolve, reject) {
      wx.login({
      success: res => {
      // console.log('code:' + res.code)   //获取到code          
      // 发送 res.code 到后台换取 openId, sessionKey
      wx.request({
        url: 'https://www.beicho.com/get_openId.php', //接口地址 
        method: 'GET',
        header: {
          'content-type': 'application/json'
        },
        data: {
          code: res.code
        },
        success: res => {          
          app.globalData.openid = res.data.openid
          app.globalData.session_key = res.data.session_key
          app.globalData.loginStr = '已登录'         
          console.log('执行完成openid:'+res.data.openid)
          resolve('success') 
         }

      })  //request  
           
    } //login success

  }) //login结束 

})  //promise结束
return p
}
//从模块内导出一个函数
module.exports.getOpenid = getOpenid;